package com.arkisv.log.util;/**
 * Created by fb on 2017/2/8.
 */

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.List;

import com.arkisv.common.model.EventLog;
import com.arkisv.common.model.StepLog;
import com.arkisv.common.util.SystemUtil;

/**
 * 全局参数或方法
 * Created by fb on 2017/2/8.
 */
public class Global {
	/**步骤日志批量插入数据库list*/
    public static final List<StepLog> BATCH_ADD_STEP_LOG_LIST = Collections.synchronizedList(new ArrayList<StepLog>(100));
	
    /**将修改失败的日志暂存*/
    public static final List<EventLog> CACHE_UPDATE_EVENTLOG_LIST = Collections.synchronizedList(new ArrayList<EventLog>(100));
    /**步骤日志内容长度*/
    public static final int STEP_CONTENT_LENGTH = 10240;
    /**参数日志内容长度*/
    public static final int PARAM_PARAMS_LENGTH = 2048;
    /**参数日志cookie长度*/
    public static final int PARAM_COOKIE_LENGTH = 2048;
    
    /**
     * 截取字符串
     * @param s 原始字符串
     * @param length 截取长度
     * @return
     */
    public static String sub(String s,int length) {
    	if(s != null && s.length() > length) {
        	return s.substring(0, length-1);
        }
    	return s;
    }
    
    /**
     * 批量插入步骤日志
     * @param stepLog
     * @param stepLogDao
     * @author fb
     * @date 2017年3月2日下午3:28:33
     */
    public static void batchAddStepLog(StepLog stepLog) {
    	// 批量插入日志
        Global.BATCH_ADD_STEP_LOG_LIST.add(stepLog);
        SystemUtil.println("添加步骤日志 -> Global.BATCH_ADD_STEP_LOG_LIST-> size: " + Global.BATCH_ADD_STEP_LOG_LIST.size());
    }
    
	/**
	 * 获取今天0点时间戳
	 * @return
	 */
	public static long getDayBeginTime() {
		Calendar c = Calendar.getInstance();
		c.set(Calendar.HOUR_OF_DAY, 0);
		c.set(Calendar.MINUTE, 0);
		c.set(Calendar.SECOND, 0);
		c.set(Calendar.MILLISECOND,0);
		return c.getTimeInMillis();
	}

}
